// to capture user actions and animation as a VIDEO
import processing.video.*;
MovieMaker mm;
int movieCounter=0;
int frameCounter=0;
Boolean captured=false, justCaptured=false;
Boolean filming=false, startedFilm=false; // to track when filming 
pt lastCapturedMouse = new pt();
int lastFrameCaptured=0; // tracks frame spacing when mouse is not moving
void captureFrame() {
  if (filming && (!keyPressed || (key!=CODED && !upper(key)))) {
    mm.addFrame(); 
    frameCounter++; 
    captured=true; 
    lastFrameCaptured=frameCount; 
    justCaptured=true; 
    lastCapturedMouse.setToMouse();
  }
} // adds frame to film if filming and upper-case key not pressed

// to show user key and mouse ACTIONS
int anchorX=0, anchorY=0; // anchor coordinates of where the mouse was pressed

void showAction() { // shows user mouse clicks and key presses (only lower-case letters)
  stroke(150, 170, 255); 
  if (mousePressed) {
    fill(250, 250, 150, 130); 
    strokeWeight(2); 
    ellipse(mouseX, mouseY, 25, 25);
  }
  else {
    fill(255, 100); 
    strokeWeight(2); 
    ellipse(mouseX, mouseY, 17, 17);
  } 
  noFill();
  if (keyPressed && key!=CODED && !upper(key)) {
    fill(0); 
    noStroke(); 
    text(key, mouseX-4, mouseY+5); 
    noFill();
  }
}
void showRubberBand() {
  if (mousePressed) {
    stroke(100, 100, 200, 150); 
    line(anchorX, anchorY, mouseX, mouseY);
  }
} 
boolean upper(char K) {
  return 64<int(K) && int(K)<91;
} // if K is uppercase

// Snapping PICTURES of the screen
PImage myFace; // picture of author's face, read from file pic.jpg in data folder
int pictureCounter=0;
Boolean snapping=false; // used to hide some text whil emaking a picture
void snapPicture() {
  saveFrame("PICTURES/P"+nf(pictureCounter++, 3)+".jpg"); 
  snapping=false;
}

// Capturing animation frames 
int animationFrameCounter=0;
boolean recording=false;    // when filming animation
Boolean capturing=false;

// enter and show TEXT
int clipX=0, clipY=0;  // location of where the clipboard text will be displayed
boolean clipPinned=false;  // when clipborad text has been pinned
String clipText="";
void scribeHeader(String S) {
  fill(0); 
  text(S, 10, 20); 
  noFill();
} // writes on screen at line i
void scribeHeaderRight(String S) {
  fill(0); 
  text(S, width-S.length()*9, 20); 
  noFill();
} // writes on screen at line i
void scribeFooter(String S) {
  fill(0); 
  text(S, 10, height-10); 
  noFill();
} // writes on screen at line i
void scribeFooter(String S, int i) {
  fill(0); 
  text(S, 10, height-10-i*20); 
  noFill();
} // writes on screen at line i
void scribe(String S, int i) {
  fill(0); 
  text(S, 10, i*20+20); 
  noFill();
} // writes on screen at line i
void scribeAtMouse(String S) {
  fill(0); 
  text(S, mouseX, mouseY); 
  noFill();
} // writes on screen near mouse
void scribeAt(String S, int x, int y) {
  fill(0); 
  text(S, x, y); 
  noFill();
} // writes on screen at (x,y)
void scribeBlack(String S, int i) {
  fill(black); 
  text(S, 20, 20+i*20); 
  noFill();
}
void scribeBlackRight(String S, int i) {
  fill(black); 
  text(S, height-20-8*S.length(), 20+i*20); 
  noFill();
}
void scribeBlack(String S) {
  fill(black); 
  text(S, 20, 20); 
  noFill();
}
void scribe(String S, float x, float y) {
  text(S, x, y);
}
void scribe(String S) {
  text(S, 20, 20);
}
void scribeMouseCoordinates() {
  fill(black); 
  text("("+mouseX+","+mouseY+")", mouseX+7, mouseY+25); 
  noFill();
}
import java.awt.Toolkit;
import java.awt.datatransfer.*;
public static String getClipboard() {   // returns content of clipboard (if it contains text) or null
  Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  try {
    if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      String text = (String)t.getTransferData(DataFlavor.stringFlavor);
      return text;
    }
  } 
  catch (UnsupportedFlavorException e) {
  } 
  catch (IOException e) {
  }
  return null;
}
public static void setClipboard(String str) { // This method writes a string to the system clipboard.
  StringSelection ss = new StringSelection(str);
  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
}
Boolean isDigit(char K) {
  int w = int(K)-48; 
  return 0<w && w<10;
}
// LOADING SVG IMAGE  
PShape bot;
void loadSVG() {
  bot = loadShape("bot1.svg");
} // include in MYsetup. The file "bot1.svg" must be in the data folder
void showSVG() { // include in MYdraw.
  float w=float(width)/612; 
  float h=float(height)/792;
  if (w>h) shape(bot, floor((width-int(h/w*width))/2), 0, floor(h/w*width)-1, height-1); 
  else shape(bot, 0, floor((height-int(w/h*height))/2), width-1, floor(w/h*height)-1);
}

